package com.atguigu.service_statistics.schedule;


import com.atguigu.commonutils.DateUtil;
import com.atguigu.service_statistics.service.StatisticsDailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    //每天凌晨1点执行方法，对数据查询并进行
    @Scheduled(cron = "0 0 1 * *?")
    public void task(){
        Date date = DateUtil.addDays(new Date(), -1);
        String s = DateUtil.formatDate(date);
        statisticsDailyService.registerCount(s);
    }
}
